<template>
	<view>
		<ttBar leftIcon="icon-back" title="店铺相册"></ttBar>
		<view class="tabBar">
			<view class="tabCnt">
				<text :class="[selectType==3?'active':'']" @tap="toggleType(3)">荣誉证书</text>
				<text :class="[selectType==1?'active':'']" @tap="toggleType(1)">教学风采</text>
				<text :class="[selectType==2?'active':'']" @tap="toggleType(2)">教学环境</text>
			</view>
			<view class="tabBox">
				<!-- 资质 -->
				<scroll-view scroll-y="true" v-if="selectType==3" :style="{'height':scHeight+'px'}">
					<view class="imgListCnt">
					<block v-for="(item,index) in imgList" :key="index">
						<image :src="item" :style="{'width':imgWidth+'px','height':imgHeight+'px'}" @tap="showImg" :data-index="index"></image>
					</block>
					
					</view>
					<emptyBox v-if="imgList.length<1"></emptyBox>
				</scroll-view>
				<!-- 荣誉 -->
				<scroll-view scroll-y="true" v-if="selectType==1" :style="{'height':scHeight+'px'}">
					<view class="imgListCnt">
					<block v-for="(item,index) in imgList" :key="index">
						<image :src="item" :style="{'width':imgWidth+'px','height':imgHeight+'px'}" @tap="showImg" :data-index="index"></image>
					</block>
					
					</view>
					<emptyBox v-if="imgList.length<1"></emptyBox>
				</scroll-view>
				<!-- 技能 -->
				<scroll-view scroll-y="true" v-if="selectType==2" :style="{'height':scHeight+'px'}">
					<view class="imgListCnt">
					<block v-for="(item,index) in imgList" :key="index">
						<image :src="item" :style="{'width':imgWidth+'px','height':imgHeight+'px'}" @tap="showImg" :data-index="index"></image>
					</block>
					
					</view>
					<emptyBox v-if="imgList.length<1"></emptyBox>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	import ttBar from "@/components/ttBar/ttBar.vue";
	import emptyBox from "@/components/emptyBox/emptyBox.vue";
	export default {
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo,
				isLogin: state => state.user.isLogin
			})
		},
		components:{ttBar,emptyBox},
		data() {
			return {
				scHeight:uni.getSystemInfoSync().screenHeight-uni.getSystemInfoSync().statusBarHeight-uni.upx2px(180),
				selectType:3,
				imgWidth:parseInt(uni.getSystemInfoSync().screenWidth*0.5) ,
				imgHeight:parseInt((uni.getSystemInfoSync().screenWidth*0.5)*0.8),
				imgList:[
					'http://placeimg.com/300/240/nature',
					'http://placeimg.com/300/240/any',
					'http://placeimg.com/300/240/animal',
				],
				shopData:null,
				id:0
				
			};
		},
		methods:{
			// 点击战术图片
			showImg(e) {
				let arr = this.imgList;
				let _index=parseInt(e.currentTarget.dataset.index);
				uni.previewImage({
					current:_index,
					urls: arr
				});
			},
			// 切换类型
			toggleType(e){
				this.selectType=e;
				let r=[];
				this.shopData.resList.forEach(x=>{
						if(x.location==parseInt(this.selectType)){
							r.push(x.url)
						}
				})
				this.imgList=r;
			},
			getData() {
				this.$store.dispatch("apiGetShopDetail",{
					id:this.id,
					userId:this.isLogin?this.userInfo.userId:0
				}).then(res=>{
					this.shopData=res.data.data;
					let r=[];
					res.data.data.resList.forEach(x=>{
						if(x.location==parseInt(this.selectType)){
							r.push(x.url)
						}
					})
					this.imgList=r;
				})
			}
		},
		onLoad(cfm) {
			this.id=cfm.id
			this.selectType=parseInt(cfm.type);
			this.getData()
			
		},
		// 下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.getData()
				uni.stopPullDownRefresh();
			}, 1500)
		}
	}
</script>

<style lang="less">
	page{
		background-color: #f4f4f4;
	}
	.tabBar{
		display: flex;
		flex-direction: column;
		.tabCnt{
			height: 90upx;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: space-around;
			border-top: 1px solid #efefef;
			
			text{
				font-size: 32upx;
				color: #202932;
				height: 90upx;
				line-height: 90upx;
				border-bottom: 3px solid rgba(0,0,0,0);
				box-sizing: border-box;
				padding: 0 10upx;
			}
			.active{
				color: #f79f21;
				border-bottom: 3px solid #f79f21;
				
			}
		}
	}
	.tabBox .imgListCnt{
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		padding: 20upx 0;
		image{
			box-sizing: border-box;
			border-radius: 20upx;
			border: 10upx solid rgba(0,0,0,0);
		}
	}
</style>
